package com.kenliang.netty.rpc.spring;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * @author KenLiang
 * @description:
 * @date Created in 3:31 PM 2019/3/16.
 */
public class NettyRpcServiceParser implements BeanDefinitionParser
{
    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext) {

        String interfaceName = element.getAttribute("interfaceName");
        String ref = element.getAttribute("ref");
        //todo 作用？
        String filter = element.getAttribute("filter");

        RootBeanDefinition beanDefinition = new RootBeanDefinition();

        beanDefinition.setBeanClass(NettyRpcService.class);
        //todo  这个不用懒加载有用吗？
        beanDefinition.setLazyInit(false);
        beanDefinition.getPropertyValues().addPropertyValue("interfaceName",interfaceName);
        beanDefinition.getPropertyValues().addPropertyValue("ref",ref);
        beanDefinition.getPropertyValues().addPropertyValue("filter",filter);
        parserContext.getRegistry().registerBeanDefinition(interfaceName,beanDefinition);
        return beanDefinition;
    }
}
